package co.fitstart.weapp.api.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.demo2do.core.persistence.GenericDaoSupport;
import com.demo2do.core.persistence.annotation.Dao;
import co.fitstart.entity.course.schedule.CourseSchedule;
import co.fitstart.entity.course.schedule.ScheduleStatus;
import co.fitstart.entity.principal.Principal;
import co.fitstart.weapp.api.dao.CourseScheduleDao;
import co.fitstart.weapp.api.service.CourseRatingService;
/**
 * @ClassName: CourseRatingServiceImpl  
 * @author: cuteHU  
 * @date: 2018年12月13日
 */
@Service("courseRatingService")
public class CourseRatingServiceImpl implements CourseRatingService {
    
    @Dao
    private CourseScheduleDao courseScheduleDao;
    
    @Autowired
    private GenericDaoSupport genericDaoSupport;
        
    /*
     * (non-Javadoc)
     * @see co.fitstart.weapp.api.service.CourseRatingService#list(co.fitstart.entity.principal.Principal, boolean, int, int)
     */
    public List<CourseSchedule> list(Principal coach, boolean rated, int begin, int length) {
        if(rated) {
            return courseScheduleDao.listRating(coach, ScheduleStatus.FINISH, begin, length);
        } else {
            return courseScheduleDao.listNotRating(coach, ScheduleStatus.FINISH, begin, length);
        }
    }

    /*
     * (non-Javadoc)
     * @see co.fitstart.weapp.api.service.CourseRatingService#load(java.lang.Long)
     */
    public CourseSchedule load(Long courseSchduleId) {
        return genericDaoSupport.load(CourseSchedule.class, courseSchduleId);
    }

    /*
     * (non-Javadoc)
     * @see co.fitstart.weapp.api.service.CourseRatingService#update(co.fitstart.entity.course.schedule.CourseSchedule, int)
     */
    public void rate(CourseSchedule courseSchedule, int grade) {
        courseSchedule.grade(grade);
        genericDaoSupport.update(courseSchedule);
    }
    
}
